/**
	Radio button form element class.
	If no value is set programatically by the time the radio button loads
	it will try to determine it's value and peers by splitting the name at _
	using the first part for the group name, and second for the value.
	
	When used with the Form class, the value can be set in the config xml.
	
	And example naming of a group might be:
	color_red
	color_blue
	color_green
	
	this would make the color group of radio buttons.
	
	Calling getValue on any of the radiobuttons will return the value of the currently
	selected one.
	

	@author Chandler McWilliams
	@version 2005-07-06
*/
class timber.ui.control.RadioButton extends timber.ui.control.Checkbox
{
	private var siblings;
	
// ===========================================================
// - CONSTRUCTOR
// ===========================================================
	public function RadioButton() {
		siblings = new Array();
		value = false;
		name = this._name.split('_')[0];
	}
	
	public function onLoad() {
		// if i don't have a value, use my name
		if (!value) setValue(this._name.split('_')[1]);
		
		// determine other members in the group
		// members must be named samename_value
		var p, me;
		for (p in this._parent) {
			me = this._parent[p];
			
			// skip me
			if (me == this) continue;

			// only count radio buttons
			if (me instanceof RadioButton) {
				if (me._name.split('_')[0] == name) {
					siblings.push(me);
				}
			}
		}
		
	}

// ===========================================================
// - ACCESORS
// ===========================================================
	public function getValue() {
		// find the selected sibling and use that one
		for (var i=0; i<siblings.length; i++) {
			if (siblings[i].isEnabled()) {
				return siblings[i].super.getValue();
			}
		}
		
		return super.getValue();
	}

// ===========================================================
// - ACTIONS
// ===========================================================
	// need to uncheck my siblings
	public function check() {
		for (var i=0; i<siblings.length; i++) {
			siblings[i].uncheck();
		}
				
		// check me
		this.gotoAndStop(2);
		state = true; 
	}


}